require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')
require('../libs/iconfont/iconfont/iconfont.css')
import Swiper, {
    Autoplay,
    Pagination
} from 'swiper'
require('../libs/swiper/swiper-bundle.min.css')
require('weui')
const weui = require('weui.js')
require('../css/home.less')

const axios = require('axios')
document.addEventListener('DOMContentLoaded', function () {
    Swiper.use([Autoplay, Pagination])
    var mySwiper = new Swiper('.swiper', {
        //direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: {
            //是否再用户操作轮播图之后禁止使用自动播放
            disableOnInteraction: false
        },

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        }

    })

//获取元素
    const rank = document.querySelector('#rank')
    const clock = document.querySelector('#clock')
    const num = document.querySelector('#num')

    //axios后台渲染
    axios.get('http://139.9.177.51:8099/headPageInfo', {
        params: {
            //参数 值
            userId: localStorage.getItem('userId')
        }

    }).then(function (res) {
        //console.log(res);
        //查找rank的位置
        const subrank = res.data.data.rank
        //console.log(rank);
        //渲染
        rank.textContent = subrank
        //查找punchIn的位置
        const punchIn=res.data.data.punchIn
        //console.log(punchIn);
        //渲染
        num.textContent=punchIn
        //查找isPunch的位置
        const subclock = res.data.data.isPunch
        //如果status等于0时
        if (res.data.status == 0) {
            //判断subclock为真时和为假时
            subclock ? clock.textContent = '今日已打卡' : clock.textContent = '今日打卡'
        }

    })
    //点击事件
    clock.addEventListener('click', function () {
        //axios后台渲染
        axios.get('http://139.9.177.51:8099/clockIn', {
            params: {
                //参数 值
                userId: localStorage.getItem('userId')
            }
            //。。。之后
        }).then(function (res) {
           

            // console.log(1);
            //如果status等于0
            if(res.data.status==0){
                //自增，渲染
                num.textContent++
                //渲染
                clock.textContent = '今日已打卡'
                //弹出警示框
                weui.toast('打卡成功',1000)
            }else{
                //弹出警示框
                weui.toast('已打卡',1000)
            }
            
        })

    })


})